<template>
  <div class="applicationIndexD">
    <el-row>
      <el-col style="margin-right: 10px" :span="24" class="content-left">
        <el-row class="handleBox">
          <el-col :span="18">
            <template>
              <el-button type="normal" @click="openEdit('add')">新增</el-button>
              <el-button type="normal" @click="openEdit('edit')"
                >编辑</el-button
              >
              <el-button type="normal" @click="del">删除</el-button>
            </template>
          </el-col>
          <el-col :span="6">
            <div class="handleIconBox">
              <el-popover
                placement="bottom"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="export_porper">
                  <!-- 导出操作区域 -->
                  <el-button @click="exportFile">导出</el-button>
                </div>
                <i
                  class="iconfont icon-export"
                  title="导出"
                  slot="reference"
                ></i>
              </el-popover>
              <!-- 导入 -->
              <el-popover
                placement="bottom"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="import_porper">
                  <!-- 导入操作区域 -->
                  <el-upload
                    accept=".xls, .xlsx"
                    ref="upload"
                    :multiple="false"
                    :before-upload="beforeUpload"
                    :show-file-list="false"
                    action
                    :limit="1"
                    :http-request="uploadFile"
                  >
                    <el-button>导入</el-button>
                  </el-upload>
                </div>
                <i
                  class="iconfont icon-import"
                  title="导入"
                  slot="reference"
                ></i>
              </el-popover>
              <el-popover
                placement="bottom"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="search_porper">
                  <el-form
                    :model="searchForm"
                    ref="searchForm"
                    label-width="90px"
                    label-position="left"
                    size="mini"
                  >
                    <el-form-item label="指标编号：">
                      <el-input
                        v-model.trim="searchForm.realName"
                        style="width: 150px"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="生效日期">
                      <el-date-picker
                        v-model="searchForm.effectDt"
                        type="date"
                        style="width: 150px"
                        placeholder="选择日期"
                        :clearable="false"
                      ></el-date-picker>
                    </el-form-item>

                    <el-form-item label="指标名称">
                      <el-input
                        style="width: 150px"
                        placeholder="请输入"
                        v-model="searchForm.cnName"
                      ></el-input>
                    </el-form-item>

                    <el-form-item label="加工方式">
                      <el-select
                        style="width: 150px"
                        v-model="searchForm.statMethodCd"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in statMethodCdOption"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="指标属性之公共特性">
                      <el-select
                        style="width: 150px"
                        v-model="searchForm.attr3"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in attr3Option"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="应用场景">
                      <el-select
                        style="width: 150px"
                        v-model="searchForm.useCase"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in useCaseOption"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="指标类型">
                      <el-select
                        style="width: 150px"
                        v-model="searchForm.zblx"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in zblxOption"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-form>
                  <div style="text-align: center; padding: 10px">
                    <el-button @click="(searchForm.page = 1), searchFunc()"
                      >查询</el-button
                    >
                    <el-button @click="searchClear">重置</el-button>
                  </div>
                </div>
                <i
                  class="iconfont icon-sousuo"
                  title="搜索"
                  slot="reference"
                ></i>
              </el-popover>
              <el-popover
                placement="bottom"
                width="150"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="operation_checkbox">
                  <el-checkbox-group v-model="checkList">
                    <el-checkbox
                      v-for="item in textData"
                      :label="item.label"
                      :key="item.prop"
                      >{{ item.label }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
                <i
                  class="iconfont icon-liebiaoshezhi"
                  title="列表设置"
                  slot="reference"
                ></i>
              </el-popover>
            </div>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      @row-click="rowClick"
      style="width: 100%"
    >
      <el-table-column
        width="55"
        type="selection"
        
      ></el-table-column>
      <el-table-column
        v-for="(item, key) in showData"
        align="center"
        :key="key"
        :prop="item.prop"
        :label="item.label"
        :show-overflow-tooltip="true"
        :render-header="item.render"
        :sortable="item.sortable"
        :formatter="item.formatter"
        :width="item.width"
        :min-width="item.minwidth"
      ></el-table-column>
    </el-table>
    <!-- 分页栏 -->
    <!-- <pagination :total="total"
                    :current="page"
                    @currentCallBackEvent="handlePaginationCurrent"
                    @refreshCallBackEvent="handlePaginationRefresh"
                    @sizesCallBackEvent="handlePaginationSizes"></pagination> -->
    <pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchForm.page"
      @refresh="searchFunc"
      :page-size="searchForm.size"
      :total="total"
    ></pagination>

    <!-- kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk -->
    <!-- kkkkkkkkkkkkkkkkkkkkkkkkk  Modal is here    kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk -->
    <!-- kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk -->
    <!-- 新增、编辑弹窗 -->
    <el-dialog
      :close-on-click-modal="false"
      width="70%"
      :title="dialogTitle"
      :visible.sync="isOpenEdit"
    >
      <el-form
        label-width="170px"
        :model="editForm"
        ref="editForm"
        :rules="editRules"
        size="small"
      >
        <p>基本信息</p>
        <el-row>
          <el-col :span="8">
            <el-form-item label="指标名称：" prop="cnName">
              <el-input
                clearable
                style="width: 200px"
                v-model.trim="editForm.cnName"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="指标编号：" prop="idxNo">
              <el-input
                clearable
                v-model.trim="editForm.idxNo"
                style="width: 200px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应用场景：" prop="useCase">
              <el-select
                clearable
                style="width: 200px"
                v-model="editForm.useCase"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in useCaseOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="指标类型：" prop="zblx">
              <el-select
                clearable
                v-model="editForm.zblx"
                style="width: 200px"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in zblxOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="指标属性之基础派生：" prop="attr2">
              <el-select
                clearable
                style="width: 200px"
                v-model="editForm.attr2"
                placeholder="请选择"
                disabled
              >
                <el-option
                  v-for="item in attr2Option"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="指标属性之共性个性：" prop="attr3">
              <el-select
                clearable
                style="width: 200px"
                v-model="editForm.attr3"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in attr3Option"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="计量单位类别：" prop="calcUnitTypeCd">
              <el-select
                clearable
                style="width: 200px"
                v-model="editForm.calcUnitTypeCd"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in calcUnitTypeCdOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="指标加工方式：" prop="statMethodCd">
              <el-select
                disabled
                style="width: 200px"
                clearable
                v-model="editForm.statMethodCd"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in statMethodCdOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="首页指标：" prop="statFreq">
              <el-select
                clearable
                style="width: 200px"
                v-model="editForm.statFreq"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in statFreqOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="指标维度：" prop="idxAttr">
              <el-checkbox-group v-model="editForm.idxAttr">
                <el-checkbox
                  v-for="idx in idxAttrOption"
                  :key="idx.fieldEn"
                  :label="idx.fieldEn"
                  >{{ idx.fieldName }}</el-checkbox
                >
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <p>指标管理</p>
        <el-row>
          <el-col :span="8">
            <el-form-item label="生效日期：" prop="effectDt">
              <el-date-picker
                v-model="editForm.effectDt"
                style="width: 200px"
                align="right"
                type="date"
                placeholder="选择日期"
                :picker-options="pickerOptions"
                @change="editForm.invalidDt = null"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="失效日期：" prop="invalidDt">
              <el-date-picker
                :disabled="editForm.effectDt == null || editForm.effectDt == ''"
                style="width: 200px"
                v-model="editForm.invalidDt"
                align="right"
                type="date"
                placeholder="选择日期"
                :picker-options="limitPickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注：" prop="memo">
              <el-input
                clearable
                v-model="editForm.memo"
                style="width: 200px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <p>加工信息</p>
        <el-row>
          <el-col :span="24">
            <el-form-item label="计算公式：" prop="calFormula">
              <el-input
                clearable
                readonly
                style="width: 400px"
                v-model="editForm.calFormula"
                placeholder="请选择"
              >
              </el-input>
              <el-button class="buttonCalu" @click="editForm.calFormula = ''">
                <i class="el-icon-close"></i>
              </el-button>
              <el-button class="buttonCalu" @click="openEditCal()">
                <i class="el-icon-edit"></i>
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="submitEdit()">保存</el-button>
        <el-button @click="isOpenEdit = false">关闭</el-button>
      </span>
    </el-dialog>

    <!-- 指标公式编辑 -->
    <el-dialog
      :close-on-click-modal="false"
      top="2vh"
      width="60%"
      title="指标公式编辑"
      :visible.sync="calEditStatus"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="基础指标查询" name="basic">
          <upper-template
            @search="(basicForm.page = 1), submitBasicForm()"
            @clear="
              (basicForm.effectDt = ''),
                (basicForm.cnName = ''),
                (basicForm.idxNo = '')
            "
          >
            <!-- 操作按钮区 -->
            <!-- 搜索区 -->
            <template slot="searchArea">
              <el-form
                :model="basicForm"
                ref="basicForm"
                label-width="100px"
                label-position="left"
                size="mini"
              >
                <el-form-item label="生效日期:">
                  <el-date-picker
                    v-model="basicForm.effectDt"
                    type="date"
                    placeholder="选择日期"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="中文名称：">
                  <el-input
                    v-model.trim="basicForm.cnName"
                    placeholder="请输入名称"
                  ></el-input>
                </el-form-item>
                <el-form-item label="指标编号：">
                  <el-input
                    v-model.trim="basicForm.idxNo"
                    placeholder="请输入编号"
                  ></el-input>
                </el-form-item>
              </el-form>
            </template>
            <!-- 显示隐藏区 -->
            <template slot="columnHide">
              <el-checkbox-group v-model="checkListBasicForm">
                <el-checkbox
                  v-for="item in textDataBasicForm"
                  :label="item.label"
                  :disabled="item.checkDisabled"
                  :key="item.prop"
                  >{{ item.label }}</el-checkbox
                >
              </el-checkbox-group>
            </template>
          </upper-template>

          <el-table
            :data="basicTableData"
            border
            max-height="300"
            size="mini"
            style="margin: 10px 0px"
            highlight-current-row
            @current-change="handleCurrentChange"
          >
            <!-- <el-table-column type="index" width="50"></el-table-column> -->
            <el-table-column
              v-if="checkListBasicForm[0]"
              prop="idxAttr"
              label="指标维度"
              align="center"
            >
            </el-table-column>
            <el-table-column
              v-if="checkListBasicForm[1]"
              prop="idxNo"
              label="指标编号"
              align="center"
            >
            </el-table-column>
            <el-table-column
              v-if="checkListBasicForm[2]"
              prop="cnName"
              label="中文名称"
              align="center"
            ></el-table-column>
            <el-table-column
              v-if="checkListBasicForm[3]"
              prop="shortEnName"
              label="英文简称"
              align="center"
            >
            </el-table-column>
          </el-table>
          <!-- <el-pagination
            @size-change="basicPageSizeChange"
            @current-change="basicCurPageChange"
            :current-page="basicPage"
            :page-sizes="[10, 50, 100, 200]"
            :page-size="basicPageSize"
            :pager-count="5"
            layout="sizes,slot,prev, pager, next ,jumper,->,total"
            background
            :total="basicTotal"
          >
            <span style="width: 15%"></span>
          </el-pagination> -->
          <pagination
            @size-change="basicPageSizeChange"
            @current-change="basicCurPageChange"
            :current-page="basicPage"
            @refresh="basicGeneralQuery"
            :page-size="basicPageSize"
            :total="basicTotal"
          >
          </pagination>
        </el-tab-pane>

        <el-tab-pane label="应用指标查询" name="app">
          <upper-template
            @search="(appForm.page = 1), submitAppForm()"
            @clear="
              (appForm.effectDt = ''),
                (appForm.cnName = ''),
                (appForm.idxNo = '')
            "
          >
            <!-- 操作按钮区 -->
            <!-- 搜索区 -->
            <template slot="searchArea">
              <el-form
                :model="appForm"
                ref="appForm"
                label-width="100px"
                label-position="left"
                size="mini"
              >
                <el-form-item label="生效日期:">
                  <el-date-picker
                    v-model="appForm.effectDt"
                    type="date"
                    placeholder="选择日期"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="中文名称：">
                  <el-input
                    v-model.trim="appForm.cnName"
                    placeholder="请输入名称"
                  ></el-input>
                </el-form-item>
                <el-form-item label="指标编号：">
                  <el-input
                    v-model.trim="appForm.idxNo"
                    placeholder="请输入编号"
                  ></el-input>
                </el-form-item>
              </el-form>
            </template>
            <!-- 显示隐藏区 -->
            <template slot="columnHide">
              <el-checkbox-group v-model="checkListAppForm">
                <el-checkbox
                  v-for="item in textDataAppForm"
                  :label="item.label"
                  :disabled="item.checkDisabled"
                  :key="item.prop"
                  >{{ item.label }}</el-checkbox
                >
              </el-checkbox-group>
            </template>
          </upper-template>
          <el-table
            :data="appTableData"
            border
            max-height="300"
            size="mini"
            style="margin: 10px 0px"
            highlight-current-row
            @current-change="handleCurrentChange"
          >
            <el-table-column
              v-if="checkListAppForm[0]"
              prop="idxAttr"
              label="指标维度"
              align="center"
            >
            </el-table-column>
            <el-table-column
              v-if="checkListAppForm[1]"
              prop="idxNo"
              label="指标编号"
              align="center"
            >
            </el-table-column>
            <el-table-column
              v-if="checkListAppForm[2]"
              prop="cnName"
              label="中文名称"
              align="center"
            ></el-table-column>
            <el-table-column
              v-if="checkListAppForm[3]"
              prop="shortEnName"
              label="英文简称"
              align="center"
            >
            </el-table-column>
          </el-table>
          <pagination
            @size-change="appPageSizeChange"
            @current-change="appCurPageChange"
            :current-page="appPage"
            @refresh="appGeneralQuery"
            :page-size="appPageSize"
            :total="appTotal"
          >
          </pagination>
        </el-tab-pane>
      </el-tabs>
      <p style="margin: 20px 0"><b>指标计算结果</b></p>
      <el-row
        style="border-radius: 4px; border: 1px solid #dcdfe6; padding: 10px"
      >
        <el-col :span="2" style="padding-top: 30px; padding-left: 10px"
          >运算符：</el-col
        >
        <el-col :span="22">
          <el-row>
            <el-button class="resetButton" @click="appendCommand('1')"
              >1</el-button
            >
            <el-button class="resetButton" @click="appendCommand('2')"
              >2</el-button
            >
            <el-button class="resetButton" @click="appendCommand('3')"
              >3</el-button
            >
            <el-button class="resetButton" @click="appendCommand('4')"
              >4</el-button
            >
            <el-button class="resetButton" @click="appendCommand('5')"
              >5</el-button
            >
            <el-button class="resetButton" @click="appendCommand('6')"
              >6</el-button
            >
            <el-button class="resetButton" @click="appendCommand('7')"
              >7</el-button
            >
            <el-button class="resetButton" @click="appendCommand('8')"
              >8</el-button
            >
            <el-button class="resetButton" @click="appendCommand('9')"
              >9</el-button
            >
            <el-button class="resetButton" @click="appendCommand('0')"
              >0</el-button
            >
            <el-button class="resetButton" @click="appendCommand('.')"
              >.</el-button
            >
            <el-button class="resetButton" @click="appendCommand('+')"
              >+</el-button
            >
            <div></div>
            <el-button class="resetButton" @click="appendCommand('-')"
              >-</el-button
            >
            <el-button class="resetButton" @click="appendCommand('*')"
              >*</el-button
            >
            <el-button class="resetButton" @click="appendCommand('/')"
              >/</el-button
            >
            <el-button class="resetButton" @click="appendCommand('(')"
              >(</el-button
            >
            <el-button class="resetButton" @click="appendCommand(')')"
              >)</el-button
            >
            <!-- </el-row>
          <el-row style="padding-top: 10px"> -->
            <el-button class="resetButton" @click="appendCommand('<')"
              >&lt;</el-button
            >
            <el-button class="resetButton" @click="appendCommand('>')"
              >&gt;</el-button
            >
            <el-button class="resetButton" @click="appendCommand('=')"
              >=</el-button
            >
            <el-button class="resetButton" @click="appendCommand('C')"
              >C</el-button
            >
            <el-button class="resetButton" @click="appendCommand('if')"
              >if</el-button
            >
            <el-button class="resetButton" @click="appendCommand('max')"
              >max</el-button
            >
            <el-button class="resetButton" @click="appendCommand('min')"
              >min</el-button
            >
            <div></div>
            <el-button class="resetButton" @click="appendCommand('avg')"
              >avg</el-button
            >
            <el-button class="resetButton" @click="appendCommand('sum')"
              >sum</el-button
            >
            <el-button class="resetButton" @click="appendCommand('count')"
              >count</el-button
            >
          </el-row>
        </el-col>
      </el-row>
      <el-row style="border-radius: 3px; border: 1px solid #dcdfe6">
        <el-input
          style="border-color: #dcdfe6"
          type="textarea"
          id="contentText"
          :autosize="{ minRows: 4, maxRows: 6 }"
          placeholder="请输入内容"
          v-model="formulaText"
        >
        </el-input>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="saveCalEdit">保存</el-button>
        <el-button size="small" @click="calEditStatus = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
//通用排序方法
const compare = (key) => {
  return (obj1, obj2) => {
    let value1 = obj1[key];
    let value2 = obj2[key];
    if (value1 < value2) {
      return 1;
    } else if (value1 > value2) {
      return -1;
    } else {
      return 0;
    }
  };
};
import moment from "moment";
import { DatasCenter } from "@/api/index";
export default {
  data() {
    return {
      searchForm: {
        page: 1,
        size: 15,
      },
      checkList: [],
      checkListAppForm: [],
      checkListBasicForm: [],

      form: {
        effectDt: new Date(), //生效日期
        idxNo: "", //指标编号
        cnName: "", //指标名称
        statMethodCd: "", //加工方式
        attr3: "", //指标属性之共性个性
        useCase: "", //使用场景
        zblx: "", //指标类型
        page: 1,
        size: 15,
      },
      qyEffectDt: "", //生效日期
      qyIdxNo: "", //指标编号
      qyCnName: "", //指标名称
      qyStatMethodCd: "", //加工方式
      qyAttr3: "", //指标属性之共性个性
      qyUseCase: "", //使用场景
      qyZblx: "", //指标类型

      excelFile: "", //上传的文件
      statMethodCdOption: [], //加工方式-选项
      attr3Option: [], //指标属性之共性个性-选项
      useCaseOption: [], //使用场景-选项
      zblxOption: [], //指标类型-选项
      tableData: [], //表格数据
      page: 1, //当前页
      size: 20, //每页size
      total: 0, //总条数
      pickerOptions: {
        //日期选择器
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      limitPickerOptions: {
        //日期选择器-限制范围
        disabledDate: (time) => {
          return time.getTime() < this.editForm.effectDt;
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      expended: false, //标识是否展开

      //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      //MMMMMMMMMMMMMMMMM 新增\编辑start MMMMMMMMMMMMMMMMMMMMMMMMM
      //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      isOpenEdit: false, //标识是否打开了新增、编辑弹窗
      addOrEdit: "", //标识是新增还是编辑
      dialogTitle: "", //标题
      selectedRow: null, //若是编辑，编辑选中的行对象
      editForm: {
        cnName: "", //指标名称
        idxNo: "", //指标编号
        useCase: "", //应用场景
        zblx: "", //指标类型
        attr2: "", //指标属性之基础派生
        attr3: "", //指标属性之共性个性
        calcUnitTypeCd: "", //计量单位类别
        statMethodCd: "", //新增-指标加工方式
        statFreq: "", //首页指标
        idxAttr: [], //指标维度
        effectDt: "", //生效日期
        invalidDt: "", //失效日期
        memo: "", //备注
        calFormula: "", //计算公式
      },
      attr2Option: [], //指标属性之基础派生选项
      calcUnitTypeCdOption: [], //计量单位类别选项
      statFreqOption: [], //首页指标选项
      idxAttrOption: [{ fieldEn: "哈哈", fieldName: "呵呵" }], //指标维度选项
      editRules: {
        //表单验证规则
         idxNo: [
          {
            required: true,
            trigger: "blur",
            validator: this.validateIdxNo,
          },
        ],
        cnName: [
          {
            required: true,
            message: "请选择指标名称",
            trigger: "change",
          },
        ],
        useCase: [
          {
            required: true,
            message: "请选择应用场景",
            trigger: "change",
          },
        ],
        zblx: [
          {
            required: true,
            message: "请选择指标类型",
            trigger: "change",
          },
        ],
        attr2: [
          {
            required: true,
            message: "请选择基础派生",
            trigger: "change",
          },
        ],
        attr3: [
          {
            required: true,
            message: "请选择共性个性",
            trigger: "change",
          },
        ],
        calcUnitTypeCd: [
          {
            required: true,
            message: "请选择计量单位",
            trigger: "change",
          },
        ],
        statMethodCd: [
          {
            required: true,
            message: "请选择加工方式",
            trigger: "change",
          },
        ],
        statFreq: [
          {
            required: true,
            message: "请选择首页指标",
            trigger: "change",
          },
        ],
        idxAttr: [
          {
            required: true,
            message: "请选择指标维度",
            trigger: ["click", "change"],
          },
        ],
        effectDt: [
          {
            required: true,
            message: "请选择生效日期",
            trigger: "change",
          },
        ],
        calFormula: [
          {
            required: true,
            message: "请选择计算公式",
            trigger: "change",
          },
        ],
      },

      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWW 新增\编辑end WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

      //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      //MMMMMMMMMMMMMMMMM 指标公式编辑start MMMMMMMMMMMMMMMMM
      //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      calEditStatus: false, //打开状态
      activeName: "basic", //初始打开的标签
      basicTableData: [], //基础指标-表格数据
      basicPageSize: 20, //基础指标-每页大小
      basicPage: 1, //基础指标-当前页
      basicTotal: 0, //基础指标-总行数
      basicForm: {
        effectDt: "", //基础指标-生效日期
        cnName: "", //基础指标-中文名称
        idxNo: "", //基础指标-指标编号
      },

      appTableData: [], //应用指标-表格数据
      appPageSize: 10, //应用指标-每页大小
      appPage: 1, //应用指标-当前页
      appTotal: 0, //应用指标-总行数
      appForm: {
        effectDt: "", //应用指标-生效日期
        cnName: "", //应用指标-中文名称
        idxNo: "", //应用指标-指标编号
      },

      formulaText: "", //编辑结果
      textData: [
        {
          prop: "effectDt",
          label: "生效日期",
          width: 125,
          sortable: true,
          align: "center",
          checkDisabled: false,
        },
        {
          prop: "invalidDt",
          label: "失效日期",
          width: 125,
          sortable: true,
          checkDisabled: false,
        },
        {
          prop: "idxAttr",
          label: "指标维度",
          checkDisabled: false,
          width: 250,
        },
        {
          prop: "idxNo",
          label: "指标编号",
          sortable: true,
          width: 120,
          checkDisabled: false,
        },
        {
          prop: "cnName",
          label: "指标名称",
          sortable: true,
          width: 100,
          checkDisabled: false,
        },
        {
          prop: "useCase",
          label: "应用场景",
          width: 150,
          checkDisabled: false,
          formatter: (row) => {
            return this.$getLabel(row.useCase, this.useCaseOption);
          },
        },

        {
          prop: "zblx",
          label: "指标类型",
          width: 100,
          checkDisabled: false,
          formatter: (row) => {
            return this.$getLabel(row.zblx, this.zblxOption);
          },
        },
        {
          prop: "idxClsAttrCd",
          label: "指标分类属性",
          width: 130,
          checkDisabled: false,
        },
        // {
        //   prop: "caliberNames",
        //   label: "统计口径",
        //   width: 130,
        //   checkDisabled: false,
        // },
        {
          prop: "calcFormula",
          label: "计算公式",
          width: 320,
          checkDisabled: false,
        },
        {
          prop: "calcUnitTypeCd",
          label: "计量单位类别",
          width: 120,
          checkDisabled: false,
          formatter: (row) => {
            return this.$getLabel(
              row.calcUnitTypeCd,
              this.calcUnitTypeCdOption
            );
          },
        },
        {
          prop: "statMethodCd",
          label: "加工方式",
          width: 120,
          checkDisabled: false,
          formatter: (row) => {
            return this.$getLabel(row.statMethodCd, this.statMethodCdOption);
          },
        },
        {
          prop: "statFreq",
          label: "首页指标",
          width: 120,
          checkDisabled: false,
          formatter: (row) => {
            return this.$getLabel(row.statFreq, this.statFreqOption);
          },
        },
        // {
        //   prop: "memo",
        //   label: "备注",
        //    width: 120,
        //   checkDisabled: false,
        // },
        {
          prop: "tabName",
          label: "结果表",
          width: 120,
          checkDisabled: false,
        },
        {
          prop: "modifyOperNo",
          label: "修订人",
          width: 120,
          checkDisabled: false,
          formatter: (row) => {
            if (row.modifyOperNo) {
              return row.modifyOperNo;
            } else {
              return "-";
            }
          },
        },
        {
          prop: "modifyTime",
          label: "修订日期",
          width: 120,
          checkDisabled: false,
          formatter: (row) => {
            if (row.modifyTime) {
              return moment(row.modifyTime).format("YYYY-MM-DD HH:mm:ss"); // 24小时制
            } else {
              return "-";
            }
          },
        },
      ],
      textDataAppForm: [
        {
          prop: "idxAttr",
          label: "指标维度",
        },
        {
          prop: "idxNo",
          label: "指标编号",
        },
        {
          prop: "cnName",
          label: "中文名称",
        },
        {
          prop: "shortEnName",
          label: "英文简称",
        },
      ],
      textDataBasicForm: [
        {
          prop: "idxAttr",
          label: "指标维度",
        },
        {
          prop: "idxNo",
          label: "指标编号",
        },
        {
          prop: "cnName",
          label: "中文名称",
        },
        {
          prop: "shortEnName",
          label: "英文简称",
        },
      ],

      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWW 指标公式编辑end WWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWW 删除start WWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWW 删除end WWWWWWWWWWWWWWWWWWWW
      //WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
    };
  },
  computed: {
    // 展示字段
    showData() {
      let arr = this.textData.map((v) => {
        return v.label;
      });
      let valArr = [],
        showData = [];
      // 选中的字段排序
      arr.forEach((element) => {
        let flag = false;
        this.checkList.forEach((e) => {
          if (e == element) {
            flag = true;
          }
        });
        if (flag) {
          valArr.push(element);
        }
      });
      // 控制表列隐藏显示
      for (let i = 0; i < this.checkList.length; i++) {
        for (let j = 0; j < this.textData.length; j++) {
          if (this.textData[j].label == valArr[i]) {
            let item = { ...this.textData[j] };
            showData.push(item);
          }
        }
      }
      return showData;
    },
  },
  created() {
    this.checkListInit();
    this.checkListInitAppForm();
    this.checkListInitBasicForm();
  },
  mounted() {
    this.$nextTick(() => {
      this.getDict();
      // this.submitForm()
      this.searchFunc();
    });
  },
  methods: {
    isIdxNoAvailable(value) {
      let myreg = /^[a-zA-Z][a-zA-Z0-9_]{0,7}$/;
      if (!myreg.test(value)) {
        return false;
      } else {
        return true;
      }
    },
     // 字段校验指标编号
    validateIdxNo(rule, value, callback) {
      if (value === "") {
        callback(new Error("请填写指标编号"));
      } else if (!this.isIdxNoAvailable(value)) {
        callback(new Error("只可输入1-8位字母数字下划线，且以字母开头"));
      } else {
        callback();
      }
    },
    rowClick(row) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    checkListInit() {
      this.checkList = this.textData.map((v) => {
        return v.label;
      });
    },
    checkListInitAppForm() {
      this.checkListAppForm = this.textDataAppForm.map((v) => {
        return v.label;
      });
    },
    checkListInitBasicForm() {
      this.checkListBasicForm = this.textDataBasicForm.map((v) => {
        return v.label;
      });
    },

    searchClear() {
      for (const key in this.searchForm) {
        this.searchForm[key] = "";
      }
      this.searchForm.page = 1;
      this.searchForm.size = 15;
    },
    getDict() {
      //字典数据
      // // 加工方式-选项
      this.$getDict("stat_method_cd").then((res) => {
        this.statMethodCdOption = res.datas;
        console.log(this.statMethodCdOption, "加工方式");
      });
      // // 指标属性之共性个性-选项
      this.$getDict("idx_attr_3").then((res) => {
        this.attr3Option = res.datas;
      });
      // // 使用场景-选项
      this.$getDict("use_case").then((res) => {
        this.useCaseOption = res.datas;
      });
      // // 指标类型-选项
      this.$getDict("zblx").then((res) => {
        this.zblxOption = res.datas;
      });
      // // 指标属性之基础派生选项-选项
      this.$getDict("idx_attr_2").then((res) => {
        this.attr2Option = res.datas;
      });
      // // 计量单位类别选项-选项
      this.$getDict("Calc_Unit_Type_Cd").then((res) => {
        this.calcUnitTypeCdOption = res.datas;
      });
      // // 首页指标选项-选项
      this.$getDict("stat_Freq").then((res) => {
        this.statFreqOption = res.datas;
      });
      // // 指标维度-选项
      DatasCenter.findFlexibleModelDefApplication()
        .then((res) => {
          if (res.code == 200) {
            this.idxAttrOption = res.data;
            console.log(res.data);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    resetForm(formName) {
      //重置表单
      this.$refs[formName].resetFields();
    },
    submitForm() {
      //提交表单
      this.page = 1;
      this.qyEffectDt = this.form.effectDt; //生效日期
      (this.qyIdxNo = this.form.idxNo), //指标编号
        (this.qyCnName = this.form.cnName), //指标名称
        (this.qyStatMethodCd = this.form.statMethodCd), //加工方式
        (this.qyAttr3 = this.form.attr3); //指标属性之共性个性
      this.qyUseCase = this.form.useCase; //使用场景
      this.qyZblx = this.form.zblx; //指标类型
      this.searchFunc();
    },
    searchFunc() {
      //通用查询-主表格
      this.$refs["searchForm"].validate((valid) => {
        if (valid) {
          //校验通过
          let data = {
            effectDt: this.qyEffectDt,
            idxNo: this.qyIdxNo,
            cnName: this.qyCnName,
            statMethodCd: this.qyStatMethodCd,
            attr3: this.qyAttr3,
            useCase: this.qyUseCase,
            zblx: this.qyZblx,
            page: this.searchForm.page,
            size: this.searchForm.size,
            total: this.total,
            sortKey: "modifyTime",
            order: "desc",
          };
          DatasCenter.findPageDefApplication(data)
            .then((res) => {
              if (res.code == 200) {
                this.handleQueryResult(res);
                console.log(res.data);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          //校验失败
          return false;
        }
      });
    },
    handleQueryResult(response) {
      //处理findPage
      response.data.sort(compare("modifyTime"));
      this.tableData = response.data;
      this.total = response.count;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchForm.size = val;
      this.searchFunc();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.searchForm.page = val;
      this.searchFunc();
    },
    handlePaginationCurrent(value) {
      //当前页改变
      this.page = Number(value);
      this.searchFunc();
      window.removeEventListener("keydown", function () {});
    },
    handlePaginationRefresh(boolean) {
      //刷新按钮
      boolean && this.searchFunc();
    },
    handlePaginationSizes(value) {
      //每页多少条改变
      this.size = Number(value);
      this.page = 1;
      this.searchFunc();
    },
    ObjDateFormatter(objDate) {
      //对象日期格式化
      if (objDate == null || objDate == "") {
        return "";
      }
      var date = new Date(objDate);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      return year + "-" + month + "-" + day;
    },
    stringDateFormatter(sDate) {
      //字符串日期格式化
      if (sDate == null || sDate == "") {
        return "";
      }
      var date = new Date(sDate);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      return year + "-" + month + "-" + day;
    },
    useCaseFormatter(value) {
      //应用场景-格式化
      if (value == null || value.trim() == "") return "";
      var some = "";
      some = this.useCaseOption.find((v) => v.code == value);
      if (some) {
        return some.name;
      } else {
        return "";
      }
    },
    zblxFormatter(value) {
      //指标类型-格式化
      if (value == null || value.trim() == "") return "";
      var some = "";
      some = this.zblxOption.find((v) => v.code == value);
      if (some) {
        return some.name;
      } else {
        return "";
      }
    },
    calcUnitTypeCdFormatter(value) {
      //计量单位类别-格式化
      if (value == null || value.trim() == "") return "";
      var some = "";
      some = this.calcUnitTypeCdOption.find((v) => v.code == value);
      if (some) {
        return some.name;
      } else {
        return "";
      }
    },
    statMethodCdFormatter(value) {
      //加工方式-格式化
      if (value == null || value.trim() == "") return "";
      var some = "";
      some = this.statMethodCdOption.find((v) => v.code == value);
      if (some) {
        return some.name;
      } else {
        return "";
      }
    },
    statFreqFormatter(value) {
      //首页指标-格式化
      if (value == null || value.trim() == "") return "";
      var some = "";
      some = this.statFreqOption.find((v) => v.code == value);
      if (some) {
        return some.name;
      } else {
        return "";
      }
    },
    beforeUpload(file) {
      //上传文件前得检查
      var name = file.name;
      var type = name.substring(name.indexOf("."), name.length);
      if (type === ".xls" || type === ".xlsx") {
        return true;
      }
      this.$message({
        message: "只能选择xls或者xlsx格式的文件上传",
        type: "warning",
        showClose: true,
      });
      return false;
    },
    uploadFile(item) {
      // 上传文件
      this.excelFile = item.file;
      let form = new FormData();
      // 文件对象
      form.append("uploadfile", this.excelFile);
      var that = this;
      DatasCenter.importApplication(form)
        .then((res) => {
          if (res.code == 200) {
            that.$message({
              type: "success",
              message: "文件：" + that.excelFile.name + "上传成功",
            });
            that.$refs.upload.clearFiles();
            that.searchFunc();
          } else {
            that.$message({
              type: "error",
              message: res.message,
            });
            that.$refs.upload.clearFiles();
          }
        })
        .catch(function () {
          that.$message({
            type: "warning",
            message: "文件内容与模板不相符，导入失败",
          });
          that.$refs.upload.clearFiles();
        });
    },
    exportFile() {
      //导出文件
      var effDT = this.ObjDateFormatter(this.form.effectDt);
      if (effDT == "") {
        effDT = this.ObjDateFormatter(new Date());
      }
      let data = {
        effectDt: effDT, //生效日期,导出此生效日期之前的数据
        idxNo: this.form.idxNo,
        cnName: this.form.cnName,
        statMethodCd: this.form.statMethodCd,
        useCase: this.form.useCase,
        zblx: this.form.zblx,
        page: 1,
        size: 90000,
      };
      //导出请求
      DatasCenter.exportApplication(data)
        .then((res) => {
          if (res) {
            var filename = decodeURI(res.headers["content-disposition"]).split(
              "="
            )[1];
            let contenttype =
              filename.substring(filename.lastIndexOf("."), filename.length) ===
              "xlsx"
                ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                : "application/vnd.ms-excel;charset=utf-8";
            var blob = new Blob([res.data], {
              type: contenttype,
            });
            if (window.navigator.msSaveOrOpenBlob) {
              navigator.msSaveBlob(blob, filename);
            } else {
              var downloadElement = document.createElement("a");
              var href = window.URL.createObjectURL(blob); //创建下载的链接
              downloadElement.href = href;
              downloadElement.download = filename; //下载后文件名
              document.body.appendChild(downloadElement);
              downloadElement.click(); //点击下载
              document.body.removeChild(downloadElement); //下载完成移除元素
              window.URL.revokeObjectURL(href); //释放掉blob对象
            }
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message({
            type: "error",
            message: "导出失败!",
          });
        });
    },

    ////////////////////////////////////////////////////////////////
    ////////////////////////新增、编辑弹窗 start///////////////////////////
    ////////////////////////////////////////////////////////////////
    openEdit(cmd) {
      //打开编辑窗
      this.addOrEdit = cmd;
      if (this.addOrEdit === "add") {
        this.selectedRow = null;
        this.dialogTitle = "新增";
        this.editForm.cnName = "";
        this.editForm.idxNo = "";
        this.editForm.useCase = "";
        this.editForm.zblx = "";
        this.editForm.attr2 = "1";
        this.editForm.attr3 = "";
        this.editForm.calcUnitTypeCd = "";
        this.editForm.statMethodCd = "0";
        this.editForm.statFreq = "";
        this.editForm.idxAttr = [];
        this.editForm.effectDt = "";
        this.editForm.invalidDt = "";
        this.editForm.memo = "";
        this.editForm.calFormula = "";
      }
      if (this.addOrEdit === "edit") {
        let selection = this.$refs.multipleTable.selection;
        if (selection.length != 1) {
          return this.$message.warning("请选择一条数据进行修改");
        }
        this.selectedRow = selection[0];
        this.dialogTitle = "编辑";
        this.editForm.cnName = this.selectedRow.cnName; //编辑-指标名称
        this.editForm.idxNo = this.selectedRow.idxNo; //编辑-指标编号
        this.editForm.useCase = this.selectedRow.useCase; //编辑-应用场景
        this.editForm.zblx = this.selectedRow.zblx; //编辑-指标类型
        //解析指标属性(基础派生\共性个性)
        var attrs = this.selectedRow.idxClsAttrCd.split("/");
        this.editForm.attr2 = this.attr2Option.find(
          (v) => v.label == attrs[0]
        ).value; //编辑-基础派生
        this.editForm.attr3 = this.attr3Option.find(
          (v) => v.label == attrs[1]
        ).value; //编辑-共性个性

        this.editForm.calcUnitTypeCd = this.selectedRow.calcUnitTypeCd; //编辑-计量单位类别
        this.editForm.statMethodCd = this.selectedRow.statMethodCd; //编辑-指标加工方式

        //解析首页指标
        this.editForm.statFreq = this.statFreqOption.find(
          (v) => v.label == this.selectedRow.statFreq
        ).value; //编辑-首页指标

        //解析指标维度
        this.editForm.idxAttr = [];
        var attrs1 = this.selectedRow.idxAttr.split(",");
        attrs1.forEach((value) => {
          this.editForm.idxAttr.push(
            this.idxAttrOption.find((v) => v.fieldName == value).fieldEn
          );
        });

        this.editForm.effectDt = new Date(this.selectedRow.effectDt); //编辑-生效日期
        this.editForm.invalidDt =
          this.selectedRow.invalidDt == null
            ? null
            : new Date(this.selectedRow.invalidDt); //编辑-失效日期
        this.editForm.memo = this.selectedRow.memo; //编辑-备注
        this.editForm.calFormula = this.selectedRow.calcFormula; //编辑-计算公式
      }
      this.$nextTick(() => {
        this.$refs["editForm"].clearValidate();
      });
      this.isOpenEdit = true;
    },
    submitEdit(val) {
      //提交保存
      var formName = val;
      if (formName == undefined) {
        formName = "editForm";
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //校验通过
          var uuid = this.addOrEdit === "edit" ? this.selectedRow.uuid : "";
          var idxDeep =
            this.addOrEdit === "edit" ? this.selectedRow.idxDeep : "";
          var idxDeep = this.addOrEdit === "edit" ? "" : "";
          var param = `cnName=${this.editForm.cnName}&idxNo=${this.editForm.idxNo}&useCase=${this.editForm.useCase}&zblx=${this.editForm.zblx}&attr3=${this.editForm.attr3}&calcUnitTypeCd=${this.editForm.calcUnitTypeCd}&statMethodCd=${this.editForm.statMethodCd}&statFreq=${this.editForm.statFreq}`;
          var idxs = "";
          for (let v of this.editForm.idxAttr) {
            idxs += v + ",";
          }
          idxs = idxs.slice(0, idxs.length - 1);
          console.log(idxs);
          param += "&idxAttr=" + idxs;
          param += `&effectDt=${this.ObjDateFormatter(
            this.editForm.effectDt
          )}&invalidDt=${this.ObjDateFormatter(this.editForm.invalidDt)}&memo=${
            this.editForm.memo
          }&calcFormula=${
            this.editForm.calFormula
          }&uuid=${uuid}&idxDeep=${idxDeep}`;
          let subData = {
            cnName: this.editForm.cnName,
            idxNo: this.editForm.idxNo,
            useCase: this.editForm.useCase,
            zblx: this.editForm.zblx,
            attr3: this.editForm.attr3,
            calcUnitTypeCd: this.editForm.calcUnitTypeCd,
            statMethodCd: this.editForm.calcUnitTypeCd,
            statFreq: this.editForm.statFreq,
            idxAttr: idxs,
            effectDt: this.ObjDateFormatter(this.editForm.effectDt),
            invalidDt: this.ObjDateFormatter(this.editForm.invalidDt),
            memo: this.editForm.memo,
            calcFormula: this.editForm.calFormula,
            uuid,
            idxDeep,
          };
          // json请求-------------------
          DatasCenter.saveDefApplication(subData)
            .then((res) => {
              if (res.code == 200) {
                this.handleEditCheckUnique(res);
                this.isOpenEdit = false;
              } else {
                this.$message({
                  showClose: true,
                  message: res.message,
                  type: "error",
                  center: true,
                });
              }
            })
            .catch((err) => {
              console.log(err);
            });
          //json请求-------------------------
        } else {
          //校验失败
          return false;
        }
      });
    },
    handleEditCheckUnique(response) {
      //处理checkUnique结果
      if (response.data == true) {
        var uuid = this.addOrEdit === "edit" ? this.selectedRow.uuid : "";
        var idxDeep = this.addOrEdit === "edit" ? "" : "";
        var param2 = {};
        param2.cnName = this.editForm.cnName;
        param2.idxNo = this.editForm.idxNo;
        param2.useCase = this.editForm.useCase;
        param2.zblx = this.editForm.zblx;
        param2.attr3 = this.editForm.attr3;
        param2.calcUnitTypeCd = this.editForm.calcUnitTypeCd;
        param2.statMethodCd = this.editForm.statMethodCd;
        param2.statFreq = this.editForm.statFreq;
        param2.attr2 = this.editForm.attr2;
        param2.attr = this.editForm.attr2 + "," + this.editForm.attr3;
        var idxs = "";
        for (let v of this.editForm.idxAttr) {
          idxs += v + ",";
        }
        idxs = idxs.slice(0, idxs.length - 1);
        param2.idxAttr = idxs;

        param2.effectDt = this.ObjDateFormatter(this.editForm.effectDt);
        param2.invalidDt = this.ObjDateFormatter(this.editForm.invalidDt);
        param2.memo = this.editForm.memo;
        param2.calcFormula = this.editForm.calFormula;
        param2.uuid = uuid;
        param2.idxDeep = idxDeep;
        // json请求-------------------
        DatasCenter.checkUniqueSaveDefApplication(param2)
          .then((res) => {
            if (res.code == 200) {
              this.isOpenEdit = false;
              this.$message({
                showClose: true,
                message: "保存成功!",
                type: "success",
                center: true,
              });
              this.searchFunc();
              return;
            } else {
              this.$message({
                showClose: true,
                message: res.message,
                type: "error",
                center: true,
              });
            }
          })
          .catch((err) => {
            console.log(err);
          });
        //json请求-------------------------
      } else {
        this.$message({
          showClose: true,
          message: "保存失败,指标编号已经存在!",
          type: "error",

          center: true,
        });
        return;
      }
    },
    editHandleSave(response) {
      //编辑-处理save结果
      if (response.code == 200) {
        this.isOpenEdit = false;
        this.$message({
          showClose: true,
          message: "保存成功!",
          type: "success",

          center: true,
        });
        this.searchFunc();
        return;
      }
      this.$message({
        showClose: true,
        message: response.message,
        type: "error",

        center: true,
      });
    },
    ////////////////////////////////////////////////////////////////
    ////////////////////////新增、编辑弹窗 end///////////////////////////
    ////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////
    ////////////////////////指标公式编辑 start///////////////////////////
    ////////////////////////////////////////////////////////////////
    openEditCal() {
      //打开指标公式编辑
      this.activeName = "basic";

      this.basicPageSize = 15;
      this.basicPage = 1;
      this.basicTotal = 0;
      this.basicForm.effectDt = new Date();
      this.basicForm.cnName = "";
      this.basicForm.idxNo = "";

      this.appPageSize = 15;
      this.appPage = 1;
      this.appTotal = 0;
      this.appForm.effectDt = new Date();
      this.appForm.cnName = "";
      this.appForm.idxNo = "";

      this.formulaText = this.editForm.calFormula.trim(); //编辑结果
      let data1 = {
        page: this.basicPage,
        size: this.basicPageSize,
        ...this.basicForm,
      };
      data1.effectDt = moment(data1.effectDt).format("YYYY-MM-DD");
      // json请求，基础指标查询-------------------
      DatasCenter.baseIndexDefFindPageApplication(data1)
        .then((res) => {
          if (res.code == 200) {
            this.handleBasicFindPage(res);
            console.log(res.data);
          }
        })
        .catch((err) => {
          console.log(err);
        });

      let data2 = {
        page: this.appPage,
        size: this.appPageSize,
        ...this.appForm,
      };
      data2.effectDt = moment(data2.effectDt).format("YYYY-MM-DD");
      // json请求，应用指标查询-------------------
      DatasCenter.deriveIndexDefFindPageApplication(data2)
        .then((res) => {
          if (res.code == 200) {
            this.handleAppFindPage(res);
            console.log(res.data);
          }
        })
        .catch((err) => {
          console.log(err);
        });
      this.calEditStatus = true;
    },
    basicGeneralQuery(val) {
      //通用查询--基础指标
      var formName = val;
      if (formName == undefined) {
        formName = "basicForm";
      }
      this.basicForm.effectDt = this.ObjDateFormatter(this.basicForm.effectDt);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //校验通过
          let data = {
            effectDt: this.basicForm.effectDt,
            cnName: this.basicForm.cnName,
            idxNo: this.basicForm.idxNo,
            size: this.basicPageSize,
            total: this.basicTotal,
            page: this.basicPage,
          };
          // json请求，基础指标查询-------------------
          DatasCenter.baseIndexDefFindPageApplication(data)
            .then((res) => {
              if (res.code == 200) {
                this.handleBasicFindPage(res);
                console.log(res.data);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          //校验失败
          return false;
        }
      });
    },
    appGeneralQuery(val) {
      //通用查询--应用指标
      var formName = val;
      if (formName == undefined) {
        formName = "appForm";
      }
      this.appForm.effectDt = this.ObjDateFormatter(this.appForm.effectDt);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //校验通过
          // json请求，应用指标查询-------------------
          let data = {
            effectDt: this.appForm.effectDt,
            cnName: this.appForm.cnName,
            idxNo: this.appForm.idxNo,
            size: this.appPageSize,
            total: this.appTotal,
            page: this.appPage,
          };
          DatasCenter.deriveIndexDefFindPageApplication(data)
            .then((res) => {
              if (res.code == 200) {
                this.handleAppFindPage(res);
                console.log(res.data);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          //校验失败
          return false;
        }
      });
    },
    handleBasicFindPage(response) {
      //处理findPage
      this.basicTableData = response.data;
      this.basicTotal = response.count;
    },
    handleAppFindPage(response) {
      //处理findPage
      this.appTableData = response.data;
      this.appTotal = response.count;
    },
    basicPageSizeChange(val) {
      //基础指标-页面大小变化
      this.basicPage = 1;
      this.basicPageSize = val;
      this.basicGeneralQuery();
    },
    basicCurPageChange(val) {
      //基础指标-当前页变化
      this.basicPage = val;
      this.basicGeneralQuery();
    },
    appPageSizeChange(val) {
      //应用指标-页面大小变化
      this.appPage = 1;
      this.appPageSize = val;
      this.appGeneralQuery();
    },
    appCurPageChange(val) {
      //应用指标-当前页变化
      this.appPage = val;
      this.appGeneralQuery();
    },
    handleCurrentChange(currentRow) {
      //表格选中行的行为
      if (currentRow == null) return;
      var contentInput = document.getElementById("contentText");
      this.insertText(contentInput, currentRow.idxNo);
    },
    appendCommand(cmd) {
      //按钮添加命令
      var str = "";
      if (cmd === "1") {
        str = "1";
      } else if (cmd === "2") {
        str = "2";
      } else if (cmd === "3") {
        str = "3";
      } else if (cmd === "4") {
        str = "4";
      } else if (cmd === "5") {
        str = "5";
      } else if (cmd === "6") {
        str = "6";
      } else if (cmd === "7") {
        str = "7";
      } else if (cmd === "8") {
        str = "8";
      } else if (cmd === "9") {
        str = "9";
      } else if (cmd === "0") {
        str = "0";
      } else if (cmd === ".") {
        str = ".";
      } else if (cmd === "+") {
        str = "+";
      } else if (cmd === "-") {
        str = "-";
      } else if (cmd === "*") {
        str = "*";
      } else if (cmd === "/") {
        str = "/";
      } else if (cmd === "(") {
        str = "(";
      } else if (cmd === ")") {
        str = ")";
      } else if (cmd === "<") {
        str = "<";
      } else if (cmd === ">") {
        str = ">";
      } else if (cmd === "=") {
        str = "=";
      } else if (cmd === "if") {
        str = "if(--条件--,--符合处理--,--不符合处理--)";
      } else if (cmd === "max") {
        str = "max()";
      } else if (cmd === "min") {
        str = "min()";
      } else if (cmd === "avg") {
        str = "avg()";
      } else if (cmd === "sum") {
        str = "sum()";
      } else if (cmd === "count") {
        str = "count()";
      } else if (cmd === "C") {
        this.formulaText = "";
        return;
      }
      var contentInput = document.getElementById("contentText");
      this.insertText(contentInput, str);
    },
    insertText(obj, str) {
      //指标内容添加
      if (
        typeof obj.selectionStart === "number" &&
        typeof obj.selectionEnd === "number"
      ) {
        var startPos = obj.selectionStart;
        var endPos = obj.selectionEnd;
        var tmpStr = obj.value;
        var cursorPos = startPos;
        obj.value =
          tmpStr.substring(0, startPos) +
          str +
          tmpStr.substring(endPos, tmpStr.length);
        cursorPos += str.length;
        obj.selectionStart = cursorPos;
        obj.selectionEnd = cursorPos;
      } else {
        obj.value += str;
      }
      this.formulaText = obj.value;
      obj.focus();
    },
    submitBasicForm(formName) {
      //基础指标-提交表单
      this.basicPage = 1;
      this.basicGeneralQuery(formName);
    },
    resetBasicForm(formName) {
      //基础指标-重置
      this.$refs[formName].resetFields();
    },
    submitAppForm(formName) {
      //应用指标-提交表单
      this.appPage = 1;
      this.appGeneralQuery(formName);
    },
    resetAppForm(formName) {
      //应用指标-重置
      this.$refs[formName].resetFields();
    },
    saveCalEdit() {
      //保存编辑结果
      this.editForm.calFormula = this.formulaText;
      this.calEditStatus = false;
    },

    ////////////////////////////////////////////////////////////////
    ////////////////////////指标公式编辑 end///////////////////////////
    ////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////
    ////////////////////////删除 start///////////////////////////
    ////////////////////////////////////////////////////////////////
    del() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      //删除按钮
      this.$confirm("删除这条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let params = {
          ids: selection.map((v) => v.uuid),
        };
        DatasCenter.removeApplication(params)
          .then((res) => {
            if (res.code == 200) {
              this.handleRemove(res);
              console.log(res.data);
            }
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    handleRemove(response) {
      //处理删除结果
      if (response.code == 200) {
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        this.searchFunc();
      } else {
        this.$message({
          type: "warning",
          message: "删除失败!",
        });
        this.searchFunc();
      }
    },
    ////////////////////////////////////////////////////////////////
    ////////////////////////删除 end///////////////////////////
    ////////////////////////////////////////////////////////////////
  },
};
</script>
<style lang="scss" scoped>
.applicationIndexD p {
  font-size: 14px;
  line-height: 40px;
  font-weight: bold;
}
.applicationIndexD >>> .buttonCalu {
  min-height: 28px;
}
.applicationIndexD >>> .resetButton {
  margin-bottom: 5px;
  min-height: 26px;
  min-width: 62px;
}
</style>
